package com.bdqn.schedule1.service;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ScheduleService {
    @Scheduled(fixedRate = 5000)
    public void scheduled1() {
        System.out.println("******scheduled1使用fixedRate执行定时任务"+new Date()+Thread.currentThread().getName());
    }

    @Scheduled(initialDelay = 1000, fixedRate = 5000)
    public void scheduled2() {
        System.out.println("******scheduled2使用initiaDelay和fixedRate执行定时任务"+new Date()+Thread.currentThread().getName());
    }

    @Scheduled(fixedDelay = 10000)
    public void scheduled3() {
        System.out.println("******scheduled3使用fixedDelay执行定时任务"+new Date()+Thread.currentThread().getName());
    }

    @Scheduled(cron = "0/20 * * * * ?")
    private void scheduled4() {
        System.out.println("******schedule4使用corn执行定时任务"+new Date()+Thread.currentThread().getName());
    }
}
